import { Injectable } from '@angular/core';
import { AppConfig } from "../config";
import { InterceptorService } from '../service/interceptor/interceptor-service';
import { InstalledCapacityRatio } from "../module/data-analysis/installed-capacity-ratio/installed-capacity-ratio.component";

@Injectable()
export class InstalledCapacityRatioService {
  private readonly param = "models";
  private get url(): string {
    return `${AppConfig.APP_RESTFUL}/${this.param}`;
  }

  constructor(private http: InterceptorService) { }

  getCapacity() : Promise<InstalledCapacityRatio[]> {
    const url = `${this.url}/sumCapacity`;
    // const url = `http://192.168.15.17:8195/webapi/v1/models/sumCapacity`;

    return this.http.get(url)
      .toPromise()
      .then(res => {
        return res.json().data as InstalledCapacityRatio[];

      })
      .catch(this.handleError);
  }

  private handleError(error: any): Promise<any> {
    return Promise.reject(error.message || error);
  }

}



// WEBPACK FOOTER //
// ./src/app/service/installed-capacity-ratio.service.ts